<?php


class ListaPropForm extends sfForm
{
  public function configure()
  {
    
     //$this->useFields(array('name'));

  /*    $chain_pais = array(
            'Pais', 'pais', array(
                'model' => 'pais',
                'table_method' => 'tmGetItems',
                'required' => false
            )
      );
      $this->widgetSchema['pais'] = new sfWidgetFormDoctrineChoiceChain(array(
        'chain' => $chain_pais,
          'item_template' => '%widget%'
      ));
      $this->validatorSchema['pais'] = new sfValidatorChoiceChain(array(
        'chain' => $chain_pais
      ));*/



      $chain_provincia = array(
          array(
              'model' => 'pais',
              'field_name' => 'id_p',
              'add_empty' => false
          ),          
          array(
              'model' => 'provincia',
              'field_name' => 'id_provincia',
              'add_empty' => false
          ),
          array(
              'model' => 'ciudad',
              'field_name' => 'id_ciudad'
          ),
          array(
              'model' => 'zona',
              'field_name' => 'id_zona'
          ));
      $this->widgetSchema['provincia'] = new sfWidgetFormDoctrineChoiceChain(array(
          'chain' => $chain_provincia,
          'item_template' => '<td><strong>%label%<span class="star">*</span></strong>: %widget%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>',
          'global_template' => '<table cellpadding="0" cellspacing="0"><tr>%items%</tr></table>'
      ));
      $this->validatorSchema['provincia'] = new sfValidatorChoiceChain(array(
          'chain' => $chain_provincia
      ));


  }


 public function updateObject($values = null)
  {
      $object = parent::updateObject($values);
      $values = $this->getValues();
      if(isset($values['provincia'])){
          foreach($values['provincia'] as $key => $value){
              $object->set($key, $value);
          }
      }
      
      return $object;
  }

 /* public function updateDefaultsFromObject()
  {
      parent::updateDefaultsFromObject();
      $object = $this->getObject();
      if($this->isNew()){
        $this->setDefault('categories', array(
            'category_id' => 1, 'sub_category_id' => 1
        ));
        $this->setDefault('location', array(
           'id_country' => 22
        ));
      }else{
         $this->setDefault('location', array(
            'id_country' => $object->getIdCountry(),
            'id_region' => $object->getIdRegion(),
            'id_city' => $object->getIdCity()
         ));

         $this->setDefault('categories', array(
            'category_id' => $object->getCategoryId(),
            'sub_category_id' => $object->getSubCategoryId(),
            'sub_sub_category_id' => $object->getSubSubCategoryId()
         ));

      }

  }*/



}
